import { createStore } from 'vuex'
const getDefaultState = () => {
  return {
    token: '',
    userInfo: {},
    tagList: [],
    cateList: []
  }
}

const store = createStore({
  state: getDefaultState(),
  mutations: {
    RESET_STATE: state => {
      Object.assign(state, getDefaultState());
    },
    CLEAR_SETTIG: (state, { key }) => {
      if (state.hasOwnProperty(key)) {
        state[key] = "";
      }
    },
    CHANGE_SETTING: (state, { key, value }) => {
      if (state.hasOwnProperty(key)) {
        state[key] = value;
      }
    }
  },
  actions: {
    clearSetting({ commit }, data) {
      commit("CLEAR_SETTIG", data);
    },
    changeSetting({ commit }, data) {
      commit("CHANGE_SETTING", data);
    }
  },
  modules: {
  },
  getters: {
    token: state => state.token,
    userInfo: state => state.userInfo,
    tagList: state => state.tagList,
    cateList: state => state.cateList,
  }
})

export default store